package com.fenghongzhang.day006;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
 * A simple {@link Fragment} subclass.
 */
public abstract class BaseFragment extends Fragment {

    private static final String TAG = "BaseFragment";

    private boolean isFragmentVisible;
    private boolean isReuseView;
    private boolean isFirstVisible;

    private View rootView;

    public BaseFragment(){}


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        Log.i(TAG, "onCreateView: ");
        rootView = inflater.inflate(getLayoutId(), container, false);
        return rootView;
    }

//    @Override
//    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
//
//        if (rootView == null) {
//            rootView = view;
//            if (getUserVisibleHint()) {
//                if (isFirstVisible) {
//                    onFragmentFirstVisible();
//                    isFirstVisible = false;
//                }
//                onFragmentVisibleChange(true);
//                isFragmentVisible = true;
//            }
//        }
//        super.onViewCreated(view, savedInstanceState);
//    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        initVariable();
    }

//    private void initVariable() {
//        isFirstVisible = true;
//        isFragmentVisible = false;
//        rootView = null;
//        isReuseView = true;
//    }

    public abstract int getLayoutId();


//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        super.setUserVisibleHint(isVisibleToUser);
//        if (rootView == null) {
//            return;
//        }
//        if (isFirstVisible && isVisibleToUser) {
//            onFragmentFirstVisible();
//            isFirstVisible = false;
//        }
//    }

//    protected void onFragmentVisibleChange(boolean isVisible) {
//
//    }
//
//    protected void onFragmentFirstVisible() {
//
//    }
//
//    protected boolean isFragmentVisible() {
//        return isFragmentVisible;
//    }
}